package com.sbl.bajw.pc.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sbl.bajw.common.web.JsonResultUtil;
import com.sbl.bajw.common.web.RequestUnit;
import com.sbl.bajw.pc.model.RoleModel;
import com.sbl.bajw.pc.service.RoleService;

@Controller
@RequestMapping("/Role")
public class RoleAction {
	
	@Resource
	private RoleService service;
	
	@RequestMapping(value = "/main")
	public ModelAndView Index(){
		ModelAndView mav = new ModelAndView("/view/manager/role/main");
		return mav;
	}
	
	@RequestMapping(value = "/list")
	public @ResponseBody String list(){
		String result = service.list();
		return result;
	}
	
	@RequestMapping(value = "/addDialog")
	public ModelAndView addDialog(){
		ModelAndView mav = new ModelAndView("/view/manager/role/addDialog");
		return mav;
	}
	
	@RequestMapping(value = "/add")
	public @ResponseBody String add(){
		RoleModel model = RequestUnit.getModel(RoleModel.class);
		service.insert(model);
		return JsonResultUtil.Success();
	}
	
	@RequestMapping(value = "/delete")
	public @ResponseBody String delete(){
		String id = RequestUnit.getString("id");
		service.delete(id);
		return JsonResultUtil.Success();
	}
}
